<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>liear gradient</title>
    <link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.min.css">
</head>

<body>

    <div class="container">
        <h1>线性渐变 linearGradient</h1>
        <ul>
            <li>defs 元素里定义渐变, 与 css 类似, offset 设置位置, stop-color 设置颜色</li>
            <li>参考示例也可以使用 style 定义样式, 不推荐, 可能会被微信公众号文章编辑器过滤掉</li>
        </ul>
    </div>

    <div class="container">
        <svg width="640" height="500" xmlns="http://www.w3.org/2000/svg">
            <defs>
                <linearGradient id="Gradient1">
                    <stop class="stop1" offset="0%" stop-color="transparent" />
                    <stop class="stop2" offset="50%" stop-color="transparent" />
                    <stop class="stop3" offset="100%" stop-color="transparent" />
                </linearGradient>
                <linearGradient id="Gradient2" x1="0" x2="0" y1="0" y2="1">
                    <stop offset="0%" stop-color="red" />
                    <stop offset="50%" stop-color="black" stop-opacity="0" />
                    <stop offset="100%" stop-color="blue" />
                </linearGradient>
                <style><![CDATA[
                    #rect1 {
                        fill: url(#Gradient1);
                    }
                    .stop1 {
                        stop-color: red;
                    }
                    .stop2 {
                        stop-color: black;
                        stop-opacity: 0;
                    }
                    .stop3 {
                        stop-color: blue;
                    }
                ]]></style>
            </defs>
            <rect id="rect1" x="10" y="10" rx="15" ry="15" width="100" height="100" />
            <rect x="10" y="120" rx="15" ry="15" width="100" height="100" fill="url(#Gradient2)" />
        </svg>
    </div>

</body>

</html>